package com.sunjs.wechat.service.impl;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sunjs.model.LyUseraddr;
import com.sunjs.wechat.dao.WxUseraddrMapper;
import com.sunjs.wechat.service.WxUseraddrService;

import net.sf.json.JSONObject;

@Service
public class WxUseraddrServiceImpl implements WxUseraddrService {

	@Autowired
	private WxUseraddrMapper wxUseraddrMapper;

    @Override
    public List<LyUseraddr> selectUseradderList(LyUseraddr lyUseraddr) {

        return wxUseraddrMapper.selectUseradderList(lyUseraddr);

    }

    @Override
    public JSONObject insert(LyUseraddr lyUseraddr) {
        // 結果
        JSONObject result = new JSONObject();
        if(wxUseraddrMapper.insert(lyUseraddr) < 1) {
            result.put("code", "1");
            result.put("msg", "系统错误");
        }else {
            result.put("code", "0");
            result.put("msg", "新增成功");
        }
        return result;
    }

    @Override
    public JSONObject updateUseraddr(LyUseraddr lyUseraddr) {

        // 結果
        JSONObject result = new JSONObject();
        LyUseraddr useraddr = wxUseraddrMapper.selectUseradderById(lyUseraddr);
        if(useraddr == null) {
            result.put("code", "1");
            result.put("msg", "数据不存在");
            return result;
        }
        if(wxUseraddrMapper.updateUseraddr(lyUseraddr)<1) {
            result.put("code", "1");
            result.put("msg", "系统错误");
        }else {
            result.put("code", "0");
            result.put("msg", "修改成功");
        }
        return result;
    }

    
    @Override
    public JSONObject deleteUseraddr(LyUseraddr lyUseraddr) {

     // 結果
        JSONObject result = new JSONObject();
        LyUseraddr useraddr = wxUseraddrMapper.selectUseradderById(lyUseraddr);
        if(useraddr == null) {
            result.put("code", "1");
            result.put("msg", "数据不存在");
            return result;
        }
        
        if(wxUseraddrMapper.deleteUseraddr(lyUseraddr)<1) {
            result.put("code", "1");
            result.put("msg", "系统错误");
        }else {
            result.put("code", "0");
            result.put("msg", "删除成功");
        }
        return result;
    }

    @Override
    public LyUseraddr selectDefault(LyUseraddr lyUseraddr) {

        return wxUseraddrMapper.selectDefault(lyUseraddr);

    }


}
